﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ModelORM;
using System.Data.Entity;
using System.Data;

namespace Zarzadzacz
{

    interface IUpdateData<T>
    {
        bool UpdateData( T dataToUpdate);
        bool DeleteData(int dataId);
    }

    interface IData<T>
    {
        List<T> GetData();
        T GetData(int dataId);
       
    }

    interface IDataSave<T>
    {
        bool SaveData( List<T> toSave);
    }

    public enum DataType { Produkt, Kadra, Klient, Rola, Kategoria, Sektor };


    public abstract class Zarzadzator<T> : IData<T>, IDataSave<T>, IUpdateData<T>
    {
        public abstract List<T> GetData();
        public abstract T GetData(int dataId);
        public abstract bool UpdateData( T dataToUpdate);
        public abstract bool DeleteData(int dataId);
        public bool SaveData( List<T> toSave){
                                            
            using (MagazynEntities context = new MagazynEntities())
            {
                try
                {
                    foreach (var entity in toSave)
                        context.AddObject(typeof(T).Name, entity);

                    context.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }

            
        }
      
        

    }
}
